package com.suliao.home.controller.information;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suliao.common.base.Result;
import com.suliao.common.base.ResultEnum;
import com.suliao.library.entity.User;
import com.suliao.library.service.UserService;
import com.suliao.home.entity.content.CompanyDO;
import com.suliao.home.service.content.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author： M1nG-CodeGenerator
 * @since： 2020-09-14 15:21:01
 * @description： 前端控制器
 * @version： 1.0
 */
@RestController
@RequestMapping("/")
@Slf4j
public class CompanyController {

    @Reference()
    public UserService userService;
    @Reference()
    public CompanyService companyService;


    @GetMapping("/user/{id}")
    public Result getUser(@PathVariable("id") Integer userId) {
        Result result = Result.ok();
        try {
            Page<User> user = userService.getUserById(new Page(1, 10), userId);
            result.setData(user);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result = Result.error("系统错误");
        }
        return result;
    }


    @GetMapping("/company")
    public Result<CompanyDO> getCompany() {
        Result result = Result.ok();
        try {
            CompanyDO company = companyService.getCompanyById(1);
            result.setData(company);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result = Result.error("系统错误");
        }
        return result;
    }

    @RequestMapping("/bulid")
    public Result<String> bulid() {
        return Result.build(ResultEnum.WAIT);
    }

    @RequestMapping("/error1")
    public Result<String> error() {
        return Result.error("出错了");
    }


}
